<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24" type="flex" align="middle">
          <a-col flex="450px">
            <a-form-item label="">
              <a-input-group compact>
                <a-select v-model="queryParam.searchField" @change="changeForceUpdate" :dropdownMatchSelectWidth="false">
                  <a-select-option value="deptName"> 部门名称 </a-select-option>
                  <a-select-option value="projectNo"> 项目编号 </a-select-option>
                  <a-select-option value="projectName"> 项目名称 </a-select-option>
                </a-select>
                <a-input-search
                  style="width: 78%"
                  v-model="queryParam.keyword"
                  @search="searchQuery"
                  placeholder="请按照关键字进行搜索"
                />
              </a-input-group>
            </a-form-item>
          </a-col>
          <a-col flex="auto">
            <span class="flex-btn-line">
              <a-button type="primary" @click="showSearchForm = true" icon="search">高级查询</a-button>
              <a-button
                type="primary"
                icon="download"
                @click="handlePostExportXls('部门参与项目得分明细报表')"
                >导出</a-button
              >
              <a-button type="primary" @click="searchReset" icon="reload">重置</a-button>
            </span>
          </a-col>
          <a-col flex="150" v-if="permissions.indexOf('proPoint:switch') > -1">
            <span>
              转换得分：<a-switch
                :defaultChecked="false"
                @change="pgChange"
                title="此按钮工程项目绩点转得分专用，用于项目得分排名。"
              />
            </span>
          </a-col>
        </a-row>
      </a-form>

      <a-modal
        :visible="showSearchForm"
        width="70vw"
        :bodyStyle="{ padding: '10px' }"
        title="高级查询"
        @ok="handleToSearch"
        @cancel="showSearchForm = false"
      >
        <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="部门名称">
                <a-input v-model="queryParam.deptName" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目编号">
                <a-input v-model="queryParam.projectNo" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="项目名称">
                <a-input v-model="queryParam.projectName" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-modal>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator"></div>

    <!-- table区域-begin -->
    <div>
      <a-table
        v-if="freshFlag"
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        :rowKey="rowKey"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
          onSelectAll: onSelectAll,
          columnWidth: 1,
        }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetails(record)">明细</a>
        </span>
      </a-table>
    </div>
    <LuckSheetPaste
      :title="'程项目绩点与得分批量导入'"
      ref="luckSheetPaste"
      :columnsExcel="columnsExcel"
      @handleOkExcel="handleOkExcel"
    ></LuckSheetPaste>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import JInput from '@/components/jeecg/JInput'
import LuckSheetPaste from '@/components/excelPaste/LuckSheetPaste'
import { httpAction, getAction, postAction } from '@/api/manage'
import { codeInfoList } from '@/api/codeInfo'
export default {
  name: 'QueryDeptPointDetails',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JInput,
    LuckSheetPaste,
  },
  data() {
    return {
      freshFlag: true,
      /* 勾选导出参数 */
      rowKey: 'rank',
      busType: 'QueryDeptPointDetails',
      /* 排序参数 */
      isorter: {
        column: null,
        order: 'desc',
      },
      description: '部门参与项目得分明细报表',
      toggleSearchStatus: true,
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        // {
        //   title: '排名',
        //   align: 'center',
        //   dataIndex: 'rank',
        // },
        {
          title: '部门名称',
          align: 'center',
          dataIndex: 'deptName',
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projectNo',
          sorter: (a, b) => a.projectNo - b.projectNo,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '项目等级',
          align: 'center',
          dataIndex: 'projectLevel',
          sorter: (a, b) => a.projectLevel - b.projectLevel,
        },
        {
          title: '项目状态',
          align: 'center',
          dataIndex: 'projectStatus',
          sorter: (a, b) => a.projectStatus - b.projectStatus,
        },
        {
          title: '项目X绩点',
          align: 'center',
          dataIndex: 'projectGradePoint',
          sorter: (a, b) => a.deptGradePointAudit - b.deptGradePointAudit,
        },
        {
          title: '项目Y绩点',
          align: 'center',
          dataIndex: 'projectGradePointBasic',
          sorter: (a, b) => a.deptGradePointAudit - b.deptGradePointAudit,
        },
        {
          title: '项目核心力值',
          align: 'center',
          dataIndex: 'projectGradePointCore',
          sorter: (a, b) => a.coreGradePointAudit - b.coreGradePointAudit,
        },
        {
          title: '分配X绩点',
          align: 'center',
          dataIndex: 'memberGradePointAudit',
          sorter: (a, b) => a.memberGradePointAudit - b.memberGradePointAudit,
        },
        {
          title: '分配Y绩点',
          align: 'center',
          dataIndex: 'deptGradePointAudit',
          sorter: (a, b) => a.deptGradePointAudit - b.deptGradePointAudit,
        },
        {
          title: '分配核心力值',
          align: 'center',
          dataIndex: 'coreGradePointAudit',
          sorter: (a, b) => a.coreGradePointAudit - b.coreGradePointAudit,
        },

        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   fixed:"right",
        //   width:147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        list: '/reportCenter/queryDeptPointDetails?deptId=' + this.$route.query.deptId,
        exportXlsUrl: '/reportCenter/exportXlsDeptPointDetails?deptId=' + this.$route.query.deptId,
      },
      dictOptions: {},
      superFieldList: [],
      columnsExcel: [
        {
          title: '导入表头',
          align: 'center',
          dataIndex: 'projectLevel',
        },
      ],
      gradePointTypeList: [],
      showSearchForm: false,
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
    }
  },
  created() {
    this.queryParam.proPointSwitch = false
    this.queryParam.deptId = this.$route.query.deptId
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleDetails(record) {
      let urlJump = this.$router.resolve({ path: '/projectReport/queryDeptPointDetails?deptId=' + record.deptId })
      window.open(urlJump.href, '_blank')
    },
    importExcelDataBtn() {
      this.$refs.luckSheetPaste.showModalExcel()
    },
    handleOkExcel(data, excelVm) {
      excelVm.handleErroMsg('操作异常:' + res.message)
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []

      this.superFieldList = fieldList
    },
    handleToSearch() {
      this.showSearchForm = false
      this.searchQuery()
    },
    searchReset() {
      this.queryParam = {}
      this.queryParam.searchField = 'deptName'
      this.queryParam.deptId = this.$route.query.deptId
      this.queryParam.proPointSwitch = false
      this.handleToSearch()
    },
    pgChange(checked) {
      this.freshFlag = false
      this.queryParam.proPointSwitch = checked
      if (checked) {
        this.columns.splice(7, 0, {
          title: 'X得分',
          align: 'center',
          dataIndex: 'pgMemberGradePointAudit',
          sorter: (a, b) => a.pgMemberGradePointAudit - b.pgMemberGradePointAudit,
        })
      } else {
        this.columns.splice(7, 1)
      }
      this.freshFlag = true
    },
  },
  mounted() {
    this.queryParam.deptId = this.$route.query.deptId
    this.queryParam.searchField = 'deptName'
  },
  watch: {
    $route: function (newRoute) {
      this.queryParam.deptId = this.$route.query.deptId
      this.handleToSearch()
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/hte-main.less';
</style>
